<?php

namespace Liuhelong\LaravelAdmin\Wechat\Actions\WechatOffiaccountCustomerService;

use Encore\Admin\Actions\RowAction;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Http\Request;

class Invite extends RowAction
{
    public $name = '邀请用户';

    public function form()
    {
		$this->text('wechat_account', '用户微信号')->required();
    }
	
	public function handle(Model $model, Request $request)
    {
		$wechat = app('liuhelong_wechat_service');
		try{
			$wechat->handle('customer_service','invite',[$model->kf_account, $request->wechat_account]);
					
			return $this->response()->success('邀请成功，等待用户确认！')->refresh();
		}catch(\Exception $e){
			return $this->response()->error($e->getMessage())->refresh();
		}
    }
}